package io.modifier.basic.emo.core

import java.util.concurrent.CancellationException

inline fun <T> retry(times: Int, block: () -> T): T {
    var throwable: Throwable? = null
    for (i in 0 until times) {
        try {
            return block()
        } catch (e: Throwable) {
            throwable = e
            if (e is CancellationException) {
                break
            }
        }
    }
    throw throwable ?: RuntimeException("failed after retry $times times")
}
